/*
题目描述：构建乘积数组
 */
public class E66 {
    public static void main(String[] args) {
        int[] A = {1,2,3,4,5,6,7};
        int[] res = multiply(A);
        for(int a : res){
            System.out.print(a + " ");
        }
        System.out.println();
    }

    public static int[] multiply(int[] A) {
        int len = A.length;
        int[] B = new int[len];
        if(len != 0){
            B[0] = 1;
            //计算下三角连乘
            for(int i = 1; i < len; i++){
                B[i] = B[i - 1] * A[i-1];
            }
            int temp = 1;
            //计算上三角
            for(int j = len - 2; j >= 0; j--){
                temp *= A[j+1];
                B[j] *= temp;
            }
        }
        return B;
    }
}
